﻿#!/bin/bash

LogPath=~/clang/clang.log
SubfixArray=("cc","cpp","c","h","hpp")

function CodeFormat()
{
    for entry in `ls $1`
    do
        LogTime=$(date "+%Y.%m.%d %H:%M:%S")
        FilePath=$1/$entry
        if [ -f $FilePath ]
        then
            if [[ ${SubfixArray[@]} =~ ${FilePath##*.} ]]
            then
                echo "$LogTime $FilePath: file, do format..." | tee -a $LogPath
                clang-format-10 --style=google  -i $FilePath
            fi
        elif [ -d $FilePath ]
        then
            echo "$LogTime $FilePath: dir, do nothing..." | tee -a $LogPath
            CodeFormat $FilePath
        else
            echo "$LogTime $FilePath: unknow, do nothing..." | tee -a $LogPath
        fi
    done
}

function main()
{
    if [ -f $LogPath ]
    then
        cat /dev/null > $LogPath
    else
        touch $LogPath
    fi

    CodeFormat /mnt/d/space_qt/programming/nowcode_hj

    CodeFormat /mnt/d/space_qt/programming/oj2

}

main

